#include <stdio.h>
#include <stdlib.h>

typedef struct node sstruct;
struct node {
    int data;
    sstruct* next;
};
sstruct* input()
{
    int a;
    sstruct* l=(sstruct*)malloc(sizeof(sstruct));
    sstruct *p;
    p=l;
    l->next=NULL;
    scanf("%d",&a);
    while (a!=0)
    {
        sstruct *q=(sstruct*)malloc(sizeof(sstruct));
        q->data=a;
        l->next=q;
        q->next=NULL;
        l=q;
        scanf("%d",&a);
    }
    return p;
}

void print(sstruct* p)
{
    while (p->next!=NULL)
    {
        p=p->next;
        printf("%d  ",p->data);

    }
}

void search(int datax,sstruct* p)
{
    sstruct *l = NULL, *q = NULL;//l负责存储学家一个元素为9的位置，q用来存储下一个元素为20的位置
    while (p->next!=NULL)
    {
        if (p->next==NULL)
        {
            printf("don't have ");
            return ;
        }
        else if (p->next->data==9)
        {
            l=p;
        }
        else if (p->next->data==datax)
        {
            q=p;
        }
        p=p->next;
    }
    if(l && q != NULL) {
        sstruct *w = NULL; // 辅助指针, 数值交换的中间变量
        if(l == q->next){
            // 处理q->next的后继
            l = l->next;
            q->next->next = l->next;
            // 处理q->next的前驱或者说l(原l->next)的后继
            l->next = q->next;
            // 处理l(原l->next)的前驱
            q->next = l;
        } else if (q == l->next) {
            // 处理l->next的后继
            q = q->next;
            l->next->next = q->next;
            // 处理l->next的前驱或者说q(原q->next)的后继
            q->next = l->next;
            // 处理q(原q->next)的前驱
            l->next = q;
        } else {
            //交换后驱
            w = l->next->next;
            l->next->next = q->next->next;
            q->next->next = w;
            //交换前驱
            w = q->next;
            q->next = l->next;
            l->next = w;
        }
    }


}


sstruct *daozhi( sstruct* pllist)
{
    struct node *p,*t;
    p=pllist->next;
    while(p->next)
    {
        t = p->next;
        p->next = t->next;
        t->next = pllist->next;
        pllist->next = t;
    }
    return pllist;
}